package view;

import java.util.List;

import model.MapTileImage;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import controller.MapController;

public class MapControl extends Canvas{
	
	private MapController mapController;
	
	private Point mapLocation;
	
	public MapControl(Shell parent, int style){		
		super(parent, SWT.DOUBLE_BUFFERED | style);
		Point size = parent.getSize();
		mapController = new MapController(size.x, size.y);
		this.addPaintListener(new PaintListener() {
			
			@Override
			public void paintControl(PaintEvent e) {
				// TODO Auto-generated method stub
				List<MapTileImage> listMapTileImage = mapController.getTileMapImage();				
				GC gc = e.gc;
				Display display = e.display;
				for (MapTileImage mapTileImage : listMapTileImage){
					Image image = mapTileImage.getImage(display);
					if (image != null){
						gc.drawImage(image, mapTileImage.getBound().getLeft(), mapTileImage.getBound().getTop());
						image.dispose();
					}
					
				}
			}
		});
	}
}
